﻿<UserControl x:Class="MVVMDemo.View.MasterView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModel="clr-namespace:MVVMDemo.ViewModel"
    Height="Auto" Width="Auto" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="107" d:DesignWidth="245">

    <UserControl.Resources>
        <DataTemplate DataType="{x:Type ViewModel:PersonViewModel}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding FirstName}" Margin="0,0,5,0"/>
                <TextBlock Text="{Binding LastName}"/>
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <DockPanel Grid.Row="0">
            <Label Content="Search:"/>
            <TextBox Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                     Margin="5">
                <TextBox.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding SearchContainsNoMatch}" Value="True">
                                <DataTrigger.Setters>
                                    <Setter Property="TextBox.Background" Value="#68FF0000"/>
                                    <Setter Property="TextBox.ToolTip" Value="No result found"/>
                                </DataTrigger.Setters>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBox.Style>
            </TextBox>
        </DockPanel>

        <ListBox Grid.Row="1"
                 ItemsSource="{Binding Persons}"
                 IsSynchronizedWithCurrentItem="True"/>

        <UniformGrid Grid.Row="2" Columns="4">
            <Button Content="Add" Command="{Binding AddCommand}"/>
            <Button Content="Remove" Command="{Binding RemoveCommand}"/>
            <Button Content="Previous" Command="{Binding PreviousCommand}"/>
            <Button Content="Next" Command="{Binding NextCommand}"/>
            <Button Content="Save XML" Command="{Binding SaveCommand}"/>
            <Button Content="Load XML" Command="{Binding LoadCommand}"/>
        </UniformGrid>
    </Grid>
</UserControl>
